Ninja Database Pro
Load<T>(Int64) Method
Example 



KellermanSoftware.NinjaDatabasePro Namespace > NinjaDbPro Class > Load Method : Load<T>(Int64) Method
Load an object from the database. The object must have a primary key property of Id or ObjectNameId as a type of long or an exception will be thrown. Example primary key: CustomerId If there is nothing found, null is returned.
Syntax
Public Overloads Function Load(Of T As {Class, New})( _
   ByVal primaryKey As Long _
) As T
Dim instance As NinjaDbPro
Dim primaryKey As Long
Dim value As T
 
value = instance.Load(Of T)(primaryKey)
public T Load<T>( 
   long primaryKey
)
where T: class, new()
public:
T^ Loadgeneric<typename T>
( 
   int64 primaryKey
) 
where T: ref class, gcnew()

Parameters

primaryKey

Type Parameters

T
Example
NinjaDbPro db = new NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName");
             
            //Licensed Mode
            //db.UserName = "John Smith 101224";
            //db.LicenseKey = "aousdf832jasf==";
             
            //Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
            //db.Storage = new MemoryDatabase(); //In memory database
            //db.Storage = new FileDatabase();  
             
            db.OpenDatabase();
            Person person = new Person();
            person.DateCreated = DateTime.Now;
            person.Name = "Greg";
            db.Save(person);
             
            Person personCopy = db.Load<Person>(person.PersonId);
             
            db.CloseDatabase();
Dim db As New NinjaDbPro("MyDatabaseDirectory", "MyDatabaseName")
             
            'Licensed Mode
            'db.UserName = "John Smith 101224";
            'db.LicenseKey = "aousdf832jasf==";
             
            'Set before OpenDatabase. Default storage is IsolatedStorageDatabase. Other options are:
            'db.Storage = new MemoryDatabase(); //In memory database
            'db.Storage = new FileDatabase();  
             
            db.OpenDatabase()
            Dim person As New Person()
            person.DateCreated = Date.Now
            person.Name = "Greg"
            db.Save(person)
             
            Dim personCopy As Person = db.Load(Of Person)(person.PersonId)
             
            db.CloseDatabase()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

NinjaDbPro Class
NinjaDbPro Members
Overload List